package au.edu.adelaide.mips_soft_core.board_interface_pc.ui;

import java.awt.BorderLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;

import au.edu.adelaide.mips_soft_core.board_interface_pc.core.Core;
import au.edu.adelaide.mips_soft_core.board_interface_pc.logger.Logger.LoggerListener;

public class LoggerPanel extends JPanel{
	
	private JTabbedPane tabbedPane = new JTabbedPane();
	
	private JTextArea all = new JTextArea();
	private JTextArea warningsErrors = new JTextArea();
	private JTextArea errorsOnly = new JTextArea();
	
	public LoggerPanel(){
		super(new BorderLayout());
		this.add(new JLabel("Logger"), BorderLayout.NORTH);
		this.add(tabbedPane, BorderLayout.CENTER);
		this.tabbedPane.addTab("All Messages", new JScrollPane(all));
		this.tabbedPane.addTab("Errors & Warnings", new JScrollPane(warningsErrors));
		this.tabbedPane.addTab("Errors Only", new JScrollPane(errorsOnly));
		all.setEditable(false);
		warningsErrors.setEditable(false);
		errorsOnly.setEditable(false);
		createListener(all, 1);
		createListener(warningsErrors, 2);
		createListener(errorsOnly, 3);
	}
	
	private void createListener(final JTextArea area, final int level){
		Core.getCore().getLogger().addListener(new LoggerListener(){

			@Override
			public int minLevel() {
				return level;
			}

			@Override
			public void message(long time, String message, int level) {
				
				area.append("Message: " + message + "\n");
				
			}
			
		});
	}
	
	

}
